Lab 24: Change Instance Type Using Terraform
During the migration process, the Nautilus DevOps team created several EC2 instances in different regions. They are currently in the process of identifying the correct resources and utilization and are making continuous changes to ensure optimal resource utilization. Recently, they discovered that one of the EC2 instances was underutilized, prompting them to decide to change the instance type. Please make sure the Status check is completed (if it's still in Initializing state) before making any changes to the instance.
-
Change the instance type from
t2.microtot2.nanofordevops-ec2instance usingterraform. -
Make sure the EC2 instance
devops-ec2is inrunningstate after the change. -
The Terraform working directory is
/home/bob/terraform. Update themain.tffile (do not create a separate.tffile) to change the instance type.
Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.
Create main.tf
# Provision EC2 instance
resource "aws_instance" "ec2" {
ami = "ami-0c101f26f147fa7fd"
instance_type = "t2.nano"
subnet_id = ""
vpc_security_group_ids = [
"sg-5ff802faa142b2739"
]
tags = {
Name = "devops-ec2"
}
}
terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve
# aws cli
aws secretsmanager get-secret-value --secret-id datacenter-secret --query SecretString